﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Skyttespill
{
    public class CollisionDetection
    {
        private Rectangle rect_check, rect_targ;
        private float VX, VY;

        public CollisionDetection(Rectangle rect_check, Rectangle rect_targ, float VX, float VY) 
        {
            this.rect_check = rect_check;
            this.rect_targ = rect_targ;
            this.VX = VX;
            this.VY = VY;
        }

        //definerer hvordan skal målet bytte retning etter kollisjon
        //1 - ble kollidert med vertikal flate - skiftes horisontal retning (X)
        //2 - ble kollidert med horisontal flate - skiftes vertikal retning (Y)
        //3 - ble kollidert med hjørne - skiftes begge to retinger (X OG Y)


        public int NewDirections()
        {
            Point a, b, c, d;

            a = new Point(rect_targ.X + rect_targ.Width / 2, rect_targ.Y);
            b = new Point(rect_targ.X + rect_targ.Width, rect_targ.Y + rect_targ.Height / 2);
            c = new Point(rect_targ.X + rect_targ.Width / 2, rect_targ.Y + rect_targ.Height);
            d = new Point(rect_targ.X, rect_targ.Y + rect_targ.Height / 2);


            if ((rect_check.Contains(a)) || (rect_check.Contains(c)))
                return 1;
            if ((rect_check.Contains(b)) || (rect_check.Contains(d)))
                return 2;

            return 3;
        }
    }
}
